
import UIKit

class RequestInfoModel: HandyJSON {
    var code: Int = 0
    var msg: String = ""
    var time: String = ""
    var data: Any?
    
    required init() {}
}

public struct UorInXNetworkError: Error {
    /// 错误码
    var code: Int
    /// 错误信息描述
    var descripton: String
    /// 当前请求信息
    var request: URLRequest?
}

struct UorInXImageModel: HandyJSON {
    var id: Int = 0
    var imageUrl: String = ""
}

struct UorInXUploadFileModel: HandyJSON {
    var contentType: String = ""
    var ossName: String = ""
    var preUrl: String = ""
}

struct UorInXFileModel: HandyJSON {
    var fileId: Int = 0
    var url: String = ""
}

enum UorInXNetworkResponseResult<Base> {
    case successful(_ models: [Base]?)
    case error(_ error: UorInXNetworkError?)
    
    var isSuccessful: Bool {
        switch self {
        case .successful:
            return true
        default:
            return false
        }
    }
    
    var models: [Base]? {
        switch self {
        case .successful(let models):
            return models
        default:
            return nil
        }
    }
    
    var model: Base? {
        models?.first
    }
    
    var error: UorInXNetworkError? {
        switch self {
        case .error(let error):
            return error
        default:
            return nil
        }
    }
    
    var errorCode: Int {
        error?.code ?? 0
    }
    
    var errorDescripton: String? {
        error?.descripton
    }
    
}

struct UorInXDefaultFuncTreeModel: HandyJSON {
    var children: [Any] = []
}
